﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime;
using UnityEngine;
using UnityEngine.UI;

public class SettingPanelToggle : MonoBehaviour
{
	public Toggle toggle;

	public Image handle;
	
	public bool isOn
	{
		get { return toggle; }
		set { toggle.isOn = value; }
	}
	

	public float onPos;
	public float offPos;

	public Sprite onSprite;
	public Sprite offSprite;

	public float animTime = 0.2f;

	public Action<bool> onToggleValue;

	ZTransformAnim m_ZTransformAnim;
	ZTransformAnim transformAnim
    {
        get
        {
			if (m_ZTransformAnim == null)
				m_ZTransformAnim = gameObject.AddComponent<ZTransformAnim>();
			return m_ZTransformAnim;

		}
    }

	private void Awake()
	{
		if(toggle == null)
			toggle = GetComponent<Toggle>();
		
	}

	public void OnToggleValueChange(bool isOn)
	{
		this.onToggleValue?.Invoke(isOn);
		
		if (isOn)
		{
			if (handle)
			{
				//transformAnim.MoveTo(handle.transform,new Vector3(onPos,0,0), .2f, null,true);
				handle.sprite = onSprite;
			}
		}
		else
		{
			if (handle)
			{
				handle.sprite = offSprite;
				//transformAnim.MoveTo(handle.transform, new Vector3(offPos, 0, 0), .2f, null,true);
			}
		}
	}
}
